Namespace persistent.Base.Customers

    Public Interface ICustomerRepresenter
        ReadOnly Property ID() As Integer
        ReadOnly Property Parent() As ICustomerRepresenter
        ReadOnly Property Children() As ICustomerRepresenter()
        ReadOnly Property CustomerStructure() As CustomerStructures
        ReadOnly Property IsActive() As Boolean
        'readonly property
    End Interface

    Public Enum CustomerRepresenterTypes
        Customer
        Contract
    End Enum

    Public Enum CustomerStructures
        Unsupported = 85
        Any = 65
        Mass = 77
        Inst = 73
        SME = 83
        Corporate = 67
    End Enum

    Public Class CustomerContractInteractions

        Public Shared Function ConvertMSISDNtoContractID(ByVal msisdn As String) As Integer
            Dim result As Object = persistent.myDBConn.ORAScalar(String.Format("select fn_msisdn_to_coid('{0}') from dual", msisdn))
            Return IIf(result Is Nothing OrElse IsDBNull(result), -1, result)
        End Function

        Public Shared Function ConvertContractIDtoCustomerID(ByVal contractID As String) As Integer
            Dim result As Object = persistent.myDBConn.ORAScalar(String.Format("select customer_id from contract_all where co_id = {0}", contractID))
            Return IIf(result Is Nothing OrElse IsDBNull(result), -1, result)
        End Function

        Public Shared Function ConvertCustomerIDtoCustcode(ByVal customerID As Integer) As String
            Dim result As Object = persistent.myDBConn.ORAScalar(String.Format("select custcode from customer_all where customer_id = {0}", customerID))
            Return IIf(result Is Nothing OrElse IsDBNull(result), String.Empty, result)
        End Function


        Public Shared Function ConvertCustcodeToCustomerID(ByVal custCode As String) As Integer
            Dim result As Object = persistent.myDBConn.ORAScalar(String.Format("select customer_id from customer_all where custcode = '{0}'", custCode))
            Return IIf(result Is Nothing OrElse IsDBNull(result), -1, result)
        End Function

        Public Shared Function ConvertCustomerIDtoContractID(ByVal customerID As Integer) As Integer()
            Dim result As DataTable = persistent.myDBConn.myORATable(String.Format("select co_id from contract_all where customer_id = {0}", customerID))
            Dim ret As New ArrayList
            For Each row As DataRow In result.Rows
                If Not IsDBNull(row("CO_ID")) Then
                    ret.Add(CInt(row("CO_ID")))
                End If
            Next

            Return CType(ret.ToArray(GetType(Integer)), Integer())
        End Function

        Public Shared Function ConvertContractIDtoMSISDN(ByVal contractID As Integer) As String
            Dim result As Object = persistent.myDBConn.ORAScalar(String.Format("select fn_coid_to_msisdn({0}) from dual", contractID))
            Return IIf(result Is Nothing OrElse IsDBNull(result), String.Empty, result)
        End Function

    End Class

End Namespace